from django.utils.encoding import smart_unicode
from django.utils import translation

def login(request):
    """
    This context processor adds a variable {{ NEXT }}, containing the URL to which a view should redirect.  For example, if we want to return to the current page after log-in, we need a link like this :  <a href="/accounts/login/?next={{ NEXT }}" />
    Safe for use with I18N URLs.  
    """
    if 'next' in request.GET:
        return { 'NEXT': smart_unicode(request.GET['next']) }
    else:
        return { 'NEXT': smart_unicode('?'.join([request.path,request.META['QUERY_STRING'].decode('utf-8')])) }

def menu_items(request):
    from d115.siemes.models import MenuItem
    return {'TOP_MENU':MenuItem.objects.filter(language=translation.get_language(), on_top=True), 'BOTTOM_MENU':MenuItem.objects.filter(language=translation.get_language(), in_footer=True)}
